package com.wondertek.common.config;

import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import com.getui.push.v2.sdk.api.StatisticApi;
import com.getui.push.v2.sdk.api.UserApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: gongjiangtao
 * @date: 2024/8/29 11:09
 * @Description: 个推推送服务配置
 * @Version: 1.0
 */
@Configuration
public class GeTuiConfig {

//    private static final String DOMAIN = "https://restapi.getui.com/v2/";
//    private static final String APPID = "tUXpdopq8s7u98MJ6XpuA9";
//    private static final String APPKEY = "ROlVWaFInV8bsw1NbyIvT6";
//    private static final String MASTERSECRET = "avhBR3fgsf6ssimY9rgbO6";
//
    @Value("${push.domain:https://restapi.getui.com/v2/}")
    private String domain;

    @Value("${push.app-id:tUXpdopq8s7u98MJ6XpuA9}")
    private String appId;

    @Value("${push.app-key:ROlVWaFInV8bsw1NbyIvT6}")
    private String appKey;

    @Value("${push.master-secret:avhBR3fgsf6ssimY9rgbO6}")
    private String masterSecret;

    /**
     * 设置配置
     *
     * @return
     */
    private GtApiConfiguration gtApiConfiguration() {
        // 设置HttpClient最大连接数
        System.setProperty("http.maxConnections", "200");

        // 创建 GeTui API 配置
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        apiConfiguration.setAppId(appId);
        apiConfiguration.setAppKey(appKey);
        apiConfiguration.setMasterSecret(masterSecret);
        apiConfiguration.setDomain(domain);
        return apiConfiguration;
    }

    @Bean
    public PushApi pushApi() {
        // 实例化 ApiHelper 对象
        ApiHelper apiHelper = ApiHelper.build(gtApiConfiguration());

        // 创建并返回 PushApi 对象
        return apiHelper.creatApi(PushApi.class);
    }

    @Bean
    public UserApi userApi() {
        // 实例化 ApiHelper 对象
        ApiHelper apiHelper = ApiHelper.build(gtApiConfiguration());

        // 创建并返回 UserApi 对象
        return apiHelper.creatApi(UserApi.class);
    }

    @Bean
    public StatisticApi statisticApi() {
        // 实例化 ApiHelper 对象
        ApiHelper apiHelper = ApiHelper.build(gtApiConfiguration());

        // 创建并返回 StatisticApi 对象
        return apiHelper.creatApi(StatisticApi.class);
    }
}
